//
//  YZMBankCardModel.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/18.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMBankCardModel.h"
#import "Mantle+Utils.h"
#import "NSString+Utils.h"
#import "YZMImageService.h"
#import <ColorUtils/ColorUtils.h>

#define DIR_FOR_BANK_ICON    @"dir_for_bank_icon"
#define NAME_FOR_BANK_ICON   @"bank_icon_for_"

@interface YZMBankCardModel()

@property (nonatomic, assign) NSInteger defaultIndex;

@end

@implementation YZMBankCardModel

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"cid":@"id",
             @"bankName":@"bank",
             @"bankCode":@"bankCode",
             @"province":@"province",
             @"city":@"city",
             @"branch":@"subbranch",
             @"cardNumber":@"cardNumber",
             @"defaultIndex":@"defaultCard",
             };
}

- (BOOL)isCompletion{
    
    if (self.province.length == 0 || self.city.length == 0  || self.branch.length == 0) {
        
        return NO;
    }
    
    return YES;
}

- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error{
    
    self = [super initWithDictionary:dictionaryValue error:error];
    if (self) {
        
        if (self.defaultIndex == 0) {
            
            self.defaultFlag = YES;
        }else{
            self.defaultFlag = NO;
        }
     
        if (self.province.length <= 1) {
            
            self.province = @"";
        }
        
        if (self.city.length <= 1) {
            
            self.city = @"";
        }
        
        if (self.branch.length <= 1) {
            
            self.branch = @"";
        }
    }
    
    return self;
}

/*获取Icon图片*/
- (UIImage *)iconImage{
    
    return [UIImage imageWithData:[YZMImageService loadImageData:DIR_FOR_BANK_ICON fileName:[NAME_FOR_BANK_ICON stringByAppendingString:self.bankName] isDir:NO] scale:2.0];
}

- (NSString *)formatString{
    
    return [self.bankName stringByAppendingFormat:@"(尾号%@)",[self.cardNumber tailNumber]];
}

- (NSString *)formatNumber{
    
    return [self.cardNumber stringByReplacingCharactersInRange: NSMakeRange(0, self.cardNumber.length-4) withString: @"**** **** **** "];
}

- (NSString *)formatdefaultCardName {
    
    if (self.defaultFlag) {
        
        return [self.bankName stringByAppendingString:@"（默认卡）"];
    }
    
    return self.bankName;
}

//@property (nonatomic, assign) long long cid;
//@property (nonatomic, copy) NSString *bankCode;
//@property (nonatomic, copy) NSString *bankName;
//@property (nonatomic, copy) NSString *province;
//@property (nonatomic, copy) NSString *city;
//@property (nonatomic, copy) NSString *branch;
//@property (nonatomic, copy) NSString *cardNumber;
//@property (nonatomic, copy) NSString *phoneNumber;
//
//@property (nonatomic, assign) BOOL defaultFlag;
//
//- (instancetype)copyWithZone:(NSZone *)zone{
//    
//    YZMBankCardModel *copy = [[[self class] allocWithZone:zone] init];
//    copy.cid = self.cid;
//    copy.bankCode = self.bankCode
//    
//    
//    YZMConfigureModel *copy = [[[self class] allocWithZone:zone] init];
//    copy.requestTime = [self.requestTime copyWithZone:zone];
//    //    copy.isHoliday = self.isHoliday;
//    copy.holidayList = [self.holidayList copyWithZone:zone];
//    copy.unHanldDeferCharge = self.unHanldDeferCharge;
//    
//    copy.balance = self.balance;
//    copy.buyCount = self.buyCount;
//    copy.token = [self.token copyWithZone:zone];
//    
//    copy.limitTimePeriods = [self.limitTimePeriods copyWithZone:zone];
//    copy.levers = [self.levers copyWithZone:zone];
//    copy.defaultStockCode = [self.defaultStockCode copyWithZone:zone];
//    copy.maxStockCount = self.maxStockCount;
//    copy.tradingMoneyList = [self.tradingMoneyList copyWithZone:zone];
//    copy.priceRisk = [self.priceRisk copyWithZone:zone];
//    copy.quitGainRatioList = [self.quitGainRatioList copyWithZone:zone];
//    copy.tradingCountRatio = self.tradingCountRatio;
//    copy.maxCountOneDay = self.maxCountOneDay;
//    copy.serviceCharge = self.serviceCharge;
//    copy.version = [self.version copyWithZone:zone];
//    copy.maxMoneyOneStock = self.maxMoneyOneStock;
//    copy.signAgreement = self.signAgreement;
//    
//    return copy;
//}

@end
